import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Root',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import("../views/Login.vue")
  },
  {
    path: '/admin',
    name: 'Admin',
    component: () => import("../views/Admin.vue"),
    children: [
      //主页路由
      {
        path: '/home',
        name: 'Home',
        component: () => import("../views/home/Home.vue")
      },
      //住户资料管理路由
      {
        path: '/householdManage',
        name: 'HouseholdManage',
        component: () => import("../views/householdManage/HouseholdManage.vue")
      },
      //投诉管理路由
      {
        path: '/complaintManage',
        name: 'ComplaintManage',
        component: () => import("../views/complaintManage/ComplaintManage.vue")
      },
      //报修管理路由
      {
        path: '/repairServiceManage',
        name: 'RepairServiceManage',
        component: () => import("../views/repairServiceManage/RepairServiceManage.vue")
      },
      //缴费管理路由
      {
        path: '/payFeesManage',
        name: 'PayFeesManage',
        component: () => import("../views/payFeesManage/PayFeesManage.vue")
      },
      //停车位管理路由
      {
        path: '/packingSpaceManage',
        name: 'PackingSpaceManage',
        component: () => import("../views/packingSpaceManage/PackingSpaceManage.vue")
      },
      //疫情防控路由
      {
        path: '/covid19Condition',
        name: 'COVID19Condition',
        component: () => import("../views/covid19Condition/COVID19Condition.vue")
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//消除多次push同一地址产生的错误
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

export default router
